﻿namespace Hidistro.SaleSystem.Comments
{
    using Hidistro.Core;
    using Hidistro.Core.Entities;
    using Hidistro.Entities.Comments;
    using Hidistro.Entities.Promotions;
    using Hidistro.Entities.Store;
    using Hidistro.Membership.Context;
    using Hidistro.SqlDal.Comments;
    using Hidistro.SqlDal.Promotions;
    using Hidistro.SqlDal.Store;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;
    using System.Web.Caching;
    using System.Xml;

    public static class CommentBrowser
    {
        public static int DeleteMemberMessages(IList<long> messageList)
        {
            return new MessageDao().DeleteMemberMessages(messageList);
        }

        public static AfficheInfo GetAffiche(int afficheId)
        {
            return new AfficheDao().GetAffiche(afficheId);
        }

        public static List<AfficheInfo> GetAfficheList()
        {
            return new AfficheDao().GetAfficheList();
        }

        public static DataSet GetAllHotKeywords()
        {
            return new HotkeywordDao().GetAllHotKeywords();
        }

        public static ArticleInfo GetArticle(int articleId)
        {
            return new ArticleDao().GetArticle(articleId);
        }

        public static ArticleCategoryInfo GetArticleCategory(int categoryId)
        {
            return new ArticleCategoryDao().GetArticleCategory(categoryId);
        }

        public static DbQueryResult GetArticleList(ArticleQuery articleQuery)
        {
            return new ArticleDao().GetArticleList(articleQuery);
        }

        public static IList<ArticleInfo> GetArticleList(int categoryId, int maxNum)
        {
            return new ArticleDao().GetArticleList(categoryId, maxNum);
        }

        public static IList<ArticleCategoryInfo> GetArticleMainCategories()
        {
            return new ArticleCategoryDao().GetMainArticleCategories();
        }

        public static XmlDocument GetArticleSubjectDocument()
        {
            string key = "ArticleSubjectFileCache-Admin";
            if (HiContext.Current.SiteSettings.UserId.HasValue)
            {
                key = string.Format("ArticleSubjectFileCache-{0}", HiContext.Current.SiteSettings.UserId.Value);
            }
            XmlDocument document = HiCache.Get(key) as XmlDocument;
            if (document == null)
            {
                string filename = HiContext.Current.Context.Request.MapPath(HiContext.Current.GetSkinPath() + "/ArticleSubjects.xml");
                document = new XmlDocument();
                document.Load(filename);
                HiCache.Max(key, document, new CacheDependency(filename));
            }
            return document;
        }

        public static DataTable GetArticlProductList(int arctid)
        {
            Pagination page = new Pagination {
                PageIndex = 1,
                PageSize = 20
            };
            return (new ArticleDao().GetRelatedArticsProducts(page, arctid).Data as DataTable);
        }

        public static IList<FriendlyLinksInfo> GetFriendlyLinksIsVisible(int? num)
        {
            return new FriendlyLinkDao().GetFriendlyLinksIsVisible(num);
        }

        public static AfficheInfo GetFrontOrNextAffiche(int afficheId, string type)
        {
            return new AfficheDao().GetFrontOrNextAffiche(afficheId, type);
        }

        public static ArticleInfo GetFrontOrNextArticle(int articleId, string type, int categoryId)
        {
            return new ArticleDao().GetFrontOrNextArticle(articleId, type, categoryId);
        }

        public static HelpInfo GetFrontOrNextHelp(int helpId, int categoryId, string type)
        {
            return new HelpDao().GetFrontOrNextHelp(helpId, categoryId, type);
        }

        public static PromotionInfo GetFrontOrNextPromoteInfo(PromotionInfo promote, string type)
        {
            return new PromotionDao().GetFrontOrNextPromoteInfo(promote, type);
        }

        public static HelpInfo GetHelp(int helpId)
        {
            return new HelpDao().GetHelp(helpId);
        }

        public static HelpCategoryInfo GetHelpCategory(int categoryId)
        {
            return new HelpCategoryDao().GetHelpCategory(categoryId);
        }

        public static IList<HelpCategoryInfo> GetHelpCategorys()
        {
            return new HelpCategoryDao().GetHelpCategorys();
        }

        public static DbQueryResult GetHelpList(HelpQuery helpQuery)
        {
            return new HelpDao().GetHelpList(helpQuery);
        }

        public static DataSet GetHelps()
        {
            return new HelpDao().GetHelps();
        }

        public static DataSet GetHelpTitleList()
        {
            return new HelpDao().GetHelps();
        }

        public static DataTable GetHotKeywords(int categoryId, int hotKeywordsNum)
        {
            return new HotkeywordDao().GetHotKeywords(categoryId, hotKeywordsNum);
        }

        public static DbQueryResult GetLeaveComments(LeaveCommentQuery query)
        {
            return new LeaveCommentDao().GetLeaveComments(query);
        }

        public static MessageBoxInfo GetMemberMessage(long messageId)
        {
            return new MessageDao().GetMemberMessage(messageId);
        }

        public static DbQueryResult GetMemberReceivedMessages(MessageBoxQuery query)
        {
            return new MessageDao().GetMemberReceivedMessages(query);
        }

        public static DbQueryResult GetMemberSendedMessages(MessageBoxQuery query)
        {
            return new MessageDao().GetMemberSendedMessages(query);
        }

        public static PromotionInfo GetPromote(int activityId)
        {
            return new PromotionDao().GetPromotion(activityId);
        }

        public static DataTable GetPromotes(Pagination pagination, int promotiontype, out int totalPromotes)
        {
            return new PromotionDao().GetPromotes(pagination, promotiontype, out totalPromotes);
        }

        public static VoteInfo GetVoteById(long voteId)
        {
            return new VoteDao().GetVoteById(voteId);
        }

        public static DataSet GetVoteByIsShow()
        {
            return new VoteDao().GetVotes(true);
        }

        public static VoteItemInfo GetVoteItemById(long voteItemId)
        {
            return new VoteDao().GetVoteItem(voteItemId);
        }

        public static IList<VoteItemInfo> GetVoteItems(long voteId)
        {
            return new VoteDao().GetVoteItems(voteId);
        }

        public static bool InsertLeaveComment(LeaveCommentInfo leave)
        {
            Globals.EntityCoding(leave, true);
            return new LeaveCommentDao().InsertLeaveComment(leave);
        }

        public static bool PostMemberMessageIsRead(long messageId)
        {
            return new MessageDao().PostMemberMessageIsRead(messageId);
        }

        public static bool SendMessage(MessageBoxInfo messageBoxInfo)
        {
            return new MessageDao().InsertMessage(messageBoxInfo);
        }

        public static int Vote(long voteItemId)
        {
            return new VoteDao().Vote(voteItemId);
        }
    }
}

